<?php
class Db_BoothMenu
{
    public static function total($condition=false) {
        static $totals;
        $key = hash('crc32b', $condition);
        if(!isset($totals[$key]))
            $totals[$key] = DB::count('booth_menu', $condition, __FILE__ . ' line ' . __LINE__);
        return $totals[$key];
    }

    public static function getBoothMenus($limit='', $condition='')
    {
        static $rooms;
        
        $key = hash('crc32b', $condition.$limit);
        
        if(!isset($rooms[$key]))
        {
            if($condition) $condition = 'WHERE '.$condition;
            $rooms[$key] =  DB::fetch_all_array("SELECT * FROM booth_menu $condition $limit", __FILE__ . ' line ' . __LINE__);
        }
        
        return $rooms[$key];
    }

    public static function selectBoothMenu($cols='*', $limit='', $condition='') {
        static $rooms;
        $key = hash('crc32b', $cols.$condition.$limit);
        if(!isset($rooms[$key])) {
            if($condition) $condition = 'WHERE '.$condition;
            $rooms[$key] =  DB::fetch_all("SELECT $cols FROM booth_menu $condition $limit", __FILE__ . ' line ' . __LINE__);
        }
        return $rooms[$key];
    }

    /**
     * @static
     * @param int $id
     * @return mixed
     */
    public static function getById($id) {
        static $room;
        if(!isset($room[$id]))
            $room[$id] = DB::select('booth_menu', 'id='.$id, __FILE__ . ' line ' . __LINE__);
        return $room[$id];
    }

    /**
     * @static
     * @param int $hotel_id
     * @return mixed
     */
    public static function getBoothMenusByBoothId($booth_id)
    {
    	static $rooms_by_hotel;
    	
    	if(!isset($rooms_by_hotel[$booth_id]))
    	{
    		$rooms_by_hotel[$booth_id] = DB::select_all('booth_menu', 'booth_id='.(int)$booth_id.' AND status=1','id', __FILE__ . ' line ' . __LINE__);
    	}
    	
    	return $rooms_by_hotel[$booth_id];
    }




    /**
     * @static
     * @param array $booth_menu
     * @return bool|int
     */
    public static function insert($booth_menu)
    {
        $id = DB::insert('booth_menu', $booth_menu, false, __FILE__ . ' line ' . __LINE__);
        return $id;
    }

    public static function update($booth_menu, $id)
    {
        $result = DB::update_id('booth_menu', $booth_menu, $id, __FILE__ . ' line ' . __LINE__);
        return $result;
    }

    public static function delBoothMenuById($id) {
        return DB::delete_id('booth_menu',$id, __FILE__ . ' line ' . __LINE__);
    }

    public static function delBoothMenus($ids) {
        return DB::update('booth_menu', array('status'=>2), 'id IN (' . implode(',', $ids) . ')', __FILE__ . ' line ' . __LINE__);
    }

    public static function updateSatus($id, $status) {
        if(is_array($id))
            return DB::update('booth_menu', array('status'=>$status), 'id IN (' . implode(',', $id) . ')', __FILE__ . ' line ' . __LINE__);
        else
            return DB::update_id('booth_menu', array('status'=>$status), $id, __FILE__ . ' line ' . __LINE__);
    }

    public static function have_permit() {
        if(User::is_admin() || User::is_root()) return true;

        return false;
    }

    public static function have_price_permit($id) {
        if(User::is_admin()|| User::is_root()) return true;

        return false;
    }




}